#include "page_manager.h"
#include "business_clock_page.h"
#include "student_page.h"
#include "couple_page.h"
#include "custom_page.h"
#include "mqtt_handler.h"

Page currentPage;

void initPageManager() {
    currentPage.type = PAGE_TYPE_BUSINESS_CLOCK;
    currentPage.isTemporary = false;
    currentPage.displayDuration = 0;
    displayPage(PAGE_TYPE_BUSINESS_CLOCK);
}

void handleCommunication() {
    handleMQTT();
}

void checkTemporaryPage() {
    if (currentPage.isTemporary) {
        unsigned long currentTime = millis();
        if (currentTime - currentPage.startTime >= currentPage.displayDuration) {
            currentPage.type = PAGE_TYPE_BUSINESS_CLOCK;
            currentPage.isTemporary = false;
            currentPage.displayDuration = 0;
            displayPage(PAGE_TYPE_BUSINESS_CLOCK);
        }
    }
}

void displayPage(int pageType) {
    switch (pageType) {
        case PAGE_TYPE_BUSINESS_CLOCK:
            displayBusinessClockPage();
            break;
        case PAGE_TYPE_STUDENT:
            displayStudentPage();
            break;
        case PAGE_TYPE_COUPLE:
            displayCouplePage();
            break;
        case PAGE_TYPE_CUSTOM:
            displayCustomPage();
            break;
        default:
            printf("Unknown Page Type");
    }
}    